package modules.lobby.view.tableListUI
{
	/**
	 *
	 * @author warden_feng
	 * 2013-5-6
	 */
	import com.feng.components.FListItem;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.utils.Dictionary;
	
	import communication.hall.HallMsgSender;
	import communication.majiang.MajiangMsgSender;
	
	import modules.lobby.data.NormalTableModel;

	public class TableListItem extends FListItem
	{
		private static var tableListItemDic:Dictionary = new Dictionary();

		public static function getInstance(listItemMc:MovieClip):TableListItem
		{
			if (tableListItemDic[listItemMc] == null)
			{
				tableListItemDic[listItemMc] = new TableListItem(listItemMc);
			}
			return tableListItemDic[listItemMc];
		}

		public static const FREETABLELIST_STATE:String = "freeTablelist";
		
		public static const CASHTABLELIST_STATE:String = "cashTableList";
		
		public static const TOURNAMENTLIST_STATE:String = "tournamentList";
		
		public function TableListItem(listItemMc:MovieClip, data:Object = null)
		{
			super(listItemMc, data);
			listItemMc.mouseChildren = false;
			listItemMc.doubleClickEnabled = true;
			listItemMc.addEventListener(MouseEvent.DOUBLE_CLICK, onDoubleClick, false, 0, true);
			listItemMc.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
		}
		
		private function get _tableDataModel():NormalTableModel
		{
			return _data as NormalTableModel;
		}

		override public function updateView():void
		{
			if (_data == null)
			{
				_skin.freeJackpotRoomId.text = "";
				_skin.freeJackpotRoomBlind.text = "";
				_skin.freeJackpotRoomLimit.text = "";
				_skin.freeJackpotRoomDiscardTimer.text = "";
				_skin.freeJackpotRoomType.text = "";
				_skin.freeJackpotRoomJackpotAble.text = "";
				_skin.playerNumTxt.text = "";
				_skin.currencyTxt.text = "";
				_skin.vppReqTxt.text = "";
			}
			else
			{
				_skin.freeJackpotRoomId.text = _tableDataModel.tableName;
				_skin.freeJackpotRoomBlind.text = _tableDataModel.minBlinds + '/' + _tableDataModel.maxBlinds;
				_skin.freeJackpotRoomLimit.text = _tableDataModel.minBuyAmount + '/' + _tableDataModel.maxBuyAmount;
				_skin.freeJackpotRoomDiscardTimer.text = _tableDataModel.responseTime + '/' + _tableDataModel.discardTime;
				_skin.freeJackpotRoomType.text = _tableDataModel.tileCount + ' Cards';
				_skin.freeJackpotRoomJackpotAble.text = "无";
				_skin.playerNumTxt.text = _tableDataModel.maxNum == 0 ? '' : (_tableDataModel.seatedNum + '/' + _tableDataModel.maxNum);
				_skin.currencyTxt.text = _tableDataModel.currency;
				_skin.vppReqTxt.text = _tableDataModel.vppRequiredLevel;
			}
		}

		/**
		 * 双击进入桌子
		 **/
		private function onDoubleClick(event:MouseEvent):void
		{
			logger("进入编号为" + _tableDataModel.tableID.toString() + "的桌子");
			MajiangMsgSender.instance.enterTable(_tableDataModel.tableID);
		}
		
		protected function onClick(event:MouseEvent):void
		{
//			switch (showState)
//			{
//				case FREETABLELIST_STATE:
//					LobbyDataModel.selectedFreeTable = _tableDataModel;
//					break;
//				case CASHTABLELIST_STATE:
//					LobbyDataModel.selectedCashTable = _tableDataModel;
//					break;
//				case TOURNAMENTLIST_STATE:
//					LobbyDataModel.selectedTournament = _tournamentModel;
//					break;
//			}
//			//请求当前卓玩家信息
//			if (_tableDataModel)
//			{
				HallMsgSender.instance.OnRecvQueryTableInfoReq(_tableDataModel.tableID);
//			}
			
		}
	}
}
